<?php
/**
 * 标签 - JBlog
 * 
 * @copyright (c) 2008-2010 JBlog (www.lisijie.org)
 * @author lisijie <lisijie86@gmail.com>
 * @version $Id: tags.php 523 2010-06-23 10:06:24Z lisijie86 $
*/

!defined('IN_JBLOG') && exit('Access Denied!');

if ( !empty($get['tagname']) ) {
	
	$tag = $db->fetch_one_array("SELECT * FROM ".tname('tag')." WHERE tagname = '$get[tagname]'");
	if ( !$tag ) {
		show_msg(__('标签不存在。'));
	}
	$page = max(1, intval($get['page']));
	$pagesize = config('pagesize');
	$offset = ($page -1 ) * $pagesize;
	$url = 'mod=tags&tagname='.rawurlencode($get['tagname']);
	$count = $tag['count'];
	if ( $count ) {
		$postids = array();
		$query = $db->query("SELECT postid FROM ".tname('tagpost')." 
		WHERE tagid = '$tag[id]' ORDER BY postid DESC LIMIT $offset, $pagesize");
		while ( $row = $db->fetch_array($query) ) {
			$postids[] = $row['postid'];
		}
		query_post('blog', 0,0," id IN (".simplode($postids).")");
	}
	
	blog('title', __('标签').':'.$get['tagname']);
	blog('keywords', __('标签').','.$get['tagname']);
	blog('description', __('标签').','.$get['tagname']);
	
} else {
	
	$tags = array();
	$query = $db->query("SELECT * FROM ".tname('tag')." WHERE `count` > 0");
	while ( $row = $db->fetch_array($query) ) {
		$tags[] = $row;
	}
	
	blog('title', __('标签'));
	blog('keywords', __('标签'));
	blog('description', __('标签'));

}

template('tags');
?>